using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace GodSoft.Models.Mapping
{
    public class LampControllerMap : EntityTypeConfiguration<LampController>
    {
        public LampControllerMap()
        {
            // Primary Key
            this.HasKey(t => new { t.ID, t.LightID });

            // Properties
            this.Property(t => t.ID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.Identity);

            this.Property(t => t.LightID)
                .HasDatabaseGeneratedOption(DatabaseGeneratedOption.None);

            this.Property(t => t.Controller_Address)
                .HasMaxLength(50);

            this.Property(t => t.Controller_Name)
                .IsRequired()
                .HasMaxLength(50);

            this.Property(t => t.Notes)
                .HasMaxLength(50);

            // Table & Column Mappings
            this.ToTable("LampController");
            this.Property(t => t.ID).HasColumnName("ID");
            this.Property(t => t.LightID).HasColumnName("LightID");
            this.Property(t => t.CollectorID).HasColumnName("CollectorID");
            this.Property(t => t.ControllerTypeID).HasColumnName("ControllerTypeID");
            this.Property(t => t.Controller_Address).HasColumnName("Controller_Address");
            this.Property(t => t.Controller_Name).HasColumnName("Controller_Name");
            this.Property(t => t.Controller_Status).HasColumnName("Controller_Status");
            this.Property(t => t.Enable).HasColumnName("Enable");
            this.Property(t => t.Notes).HasColumnName("Notes");

            // Relationships
            this.HasRequired(t => t.Collector)
                .WithMany(t => t.LampControllers)
                .HasForeignKey(d => d.CollectorID);
            this.HasRequired(t => t.DeviceType)
                .WithMany(t => t.LampControllers)
                .HasForeignKey(d => d.ControllerTypeID);
            this.HasRequired(t => t.Light)
                .WithMany(t => t.LampControllers)
                .HasForeignKey(d => d.LightID);

        }
    }
}
